package com.levy.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.levy.domain.LoginLog;

/**
 * 用户登录日志数据访问对象
 *
 * @author liwei515
 */
@Repository  // 通过Spring注解定义一个DAO
public class LoginLogDao {

  private JdbcTemplate jdbcTemplate;

  private final static String INSERT_LOGIN_LOG_SQL = " INSERT INTO t_login_log(user_id, ip, login_datetime) VALUES(?, ?, ?) ";

  /**
   * set方法注入JdbcTemplate的Bean
   *
   * @param jdbcTemplate Spring对JDBC封装的模板
   */
  @Autowired
  public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
  }

  /**
   * 插入用户登录日志
   *
   * @param loginLog 用户登录日志实体对象
   */
  public void insertLoginLog(LoginLog loginLog) {
    Object[] args = { loginLog.getLoginLogId(), loginLog.getIp(), loginLog.getLoginDate() };
    jdbcTemplate.update(INSERT_LOGIN_LOG_SQL, args);
  }
}
